#include "widget.h"
#include "ui_widget.h"

#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    thread =new MyThread(this);
    connect(thread,&MyThread::notify,this,&Widget::timeSec);

    thread->start();

//    MyThreadAdd th1;
//    MyThreadAdd th2;

//    th1.start();
//    th2.start();

//    th1.wait();
//    th2.wait();

//    qDebug()<<MyThreadAdd::num;
//    ui->label->setText(QString::number(MyThreadAdd::num));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::timeSec()
{
    int value=ui->lcdNumber->intValue();
    --value;
    ui->lcdNumber->display(value);
}


void Widget::on_pushButton_clicked()
{
    //不可以直接这么写，因为执行此操作按钮的槽函数结束后才会执行
    MyThreadAdd::num=0;
    ui->label->setText(QString::number(MyThreadAdd::num));
    //立即刷新
    QCoreApplication::processEvents();
    //qApp->processEvents();//qApp是一个宏，替换完之后与上面等效
    //ui->label->repaint();//重新绘制Label
    MyThreadAdd th1;
    MyThreadAdd th2;

    th1.start();
    th2.start();

    th1.wait();
    th2.wait();

    qDebug()<<MyThreadAdd::num;
    ui->label->setText(QString::number(MyThreadAdd::num));
}
